# deploy.sh
#!/bin/bash

# 配置变量
LOCAL_JAR="F:/companycode/javaprogram/jdvop/target/jdvop-0.0.1-SNAPSHOT.jar"
REMOTE_HOST="root@47.99.179.156"
REMOTE_PATH="/data/project"
JAVA_PATH="/data/profile/jdk1.8.0_161/bin/java"

# 1. 上传 jar
echo "📤 正在上传 jar 文件..."
scp "$LOCAL_JAR" "$REMOTE_HOST:$REMOTE_PATH/"
if [ $? -ne 0 ]; then
  echo "❌ 上传失败！"
  exit 1
fi

# 2. 远程重启服务
echo "🚀 正在重启服务..."
ssh "$REMOTE_HOST" "
  cd $REMOTE_PATH &&
  pkill -f jdvop-0.0.1-SNAPSHOT.jar || true &&
  nohup $JAVA_PATH -jar jdvop-0.0.1-SNAPSHOT.jar > app.log 2>&1 &
"

echo "✅ 部署完成！"